##################################################################

# Gautam Nair
# gautam.nair@yale.edu
# Misperceptions of Relative Affluence and Support for International Transfers
# Make Table 14: Ordered Logit for Ordinal Variables

##################################################################

# setwd("")

##################################################################
# loading packages
##################################################################

library(MASS)
library(Hmisc)
library(foreign)
library(sandwich)
library(lmtest)
library(numDeriv)
library(stargazer)
library(ggplot2)
library(plyr)
library(gridExtra)
library(ri)
library(dplyr)
library(scales)

##################################################################

rm(list=ls())

data.working <- readRDS("d_r_cleaned_analysis_dataset.Rda")

data.working$q8 <-factor(data.working$q8)
data.working$q11 <-factor(data.working$q11)

reg.model.1 <- polr(q8 ~ group3 + group2, data = data.working, Hess=TRUE)
summary(reg.model.1)

reg.model.2 <- polr(q11 ~ group3 + group2, data = data.working, Hess=TRUE)
summary(reg.model.2)

varlabels <-       c("Information", "Salience")
spectitle <- c("Ordered Logistic Models for Support for Foreign Economic Assistance and Reductions in Agricultural Tariffs and Subsidies")
outputfile <- c("tf_t_14_ologit_table.txt")
columnlabels <-c("Foreign Aid Ordinal (1-5)", "Agricultural Trade Protections (1-4)")
depvarcaption <- c("Ordinal Logit Models for Support for Foreign Economic Assistance and Reductions in Agricultural Tariffs and Subsidies")

stargazer(reg.model.1, reg.model.2,
         title= spectitle,
          out=outputfile,
          no.space=TRUE, 
          type="text",
          model.numbers= TRUE,
         notes.append=FALSE,
         notes=c("$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01"),
          align=FALSE,
         covariate.labels=varlabels,
          header= FALSE,
          font.size="footnotesize",
          model.names=TRUE,
          digits=2,
          column.labels  = columnlabels,
          dep.var.caption  = "",
          dep.var.labels.include=FALSE,
         df=TRUE,
         single.row=TRUE,
         report="vc*st",
         ord.intercepts=TRUE
)   

